package com.caine.androidtask.launcher;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.caine.androidtask.R;

public class ListDataAdapter extends BaseAdapter {
	private CheckBox view_classid;
	private TextView view_classname;
	private ImageView view_image;
	private List<AppInfo> list;	
	private LayoutInflater layoutInflater;

	public ListDataAdapter(Context context, List<AppInfo> list) {		
		this.list = list;
		this.layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return this.list.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
    
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		convertView = layoutInflater.inflate(R.layout.caine_launcher_list,parent, false);
		view_image = (ImageView) convertView.findViewById(R.id.view_image);
		view_classname = (TextView) convertView.findViewById(R.id.view_classname);
		view_classid = (CheckBox) convertView.findViewById(R.id.view_classid);
		view_classname.setText(list.get(position).getClassName());
		view_image.setImageDrawable(convertView.getResources().getDrawable(list.get(position).getIcon()));
		view_classid.setId(position);
		convertView.setBackgroundDrawable(convertView.getResources().getDrawable(R.drawable.caine_launcher_selector));
		return convertView;
	}

}
